URIEncoding和useBodyEncodingForURI详解 |
您所在的位置:网站首页 › study on和work on › URIEncoding和useBodyEncodingForURI详解 |
之前关于编码的问题已经总结过两次了,有些地方写的很粗略。http://blog.itpub.net/29254281/viewspace-775925/http://blog.itpub.net/29254281/viewspace-1063133/Tomcat解决请求乱码可以使用URIEncoding和useBodyEncodingForURI.下面是两个参数的具体说明,参见ApacheTomcat官方手册。 URIEncoding This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used. useBodyEncodingForURI This specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding. This setting is present for compatibility with Tomcat 4.1.x, where the encoding specified in the contentType, or explicitly set using Request.setCharacterEncoding method was also used for the parameters from the URL. The default value is false.http://tomcat.apache.org/tomcat-7.0-doc/config/http.html
下表是三种浏览器的编码情况。其中IE的URI编码可以调整为UTF8。 默认URI编码 默认查询参数编码 谷歌 UTF8 UTF8 火狐 UTF8 GBK IE GBK GBK1.Tomcat的URIEncoding设置为UTF8谷歌正常火狐可以请求到资源,但是查询参数的中文为乱码IE不能请求到资源 测试代码如下 2.将IE的URI编码设置为UTF8,开启useBodyEncodingForURI,并设置request的字符集为GBK。 实验得出的结论是1.URIEncoding和useBodyEncodingForURI都可以处理中文乱码的问题2.浏览器对于URI和查询参数可能使用两种不同的编码方式,这种情况下,可以使用useBodyEncodingForURI调整查询参数的编码。 参考:http://www.ibm.com/developerworks/cn/java/j-lo-chinesecoding/ |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |